package com.seeTools.boot.pc.service.sys.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seeTools.boot.api.entity.sys.SysUserRole;
import com.seeTools.boot.common.core.PageQuery;
import com.seeTools.boot.pc.mapper.sys.SysUserRoleMapper;
import com.seeTools.boot.pc.service.sys.ISysUserRoleService;
import com.seeTools.boot.pc.util.PageQueryHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户角色关联表 服务实现类
 * </p>
 *
 * @author FallenDust
 * @since 2023-05-15
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    @Resource
    private PageQueryHelper<SysUserRole> pageQueryHelper;

    @Override
    public Page<SysUserRole> pageInfo(PageQuery<SysUserRole> pageQuery) {
        SysUserRole dataObj = pageQuery.getDataObj();
        // 根据查询参数组装查询wrapper
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper = queryWrapper.lambda();
        return pageQueryHelper.pageInfo(this, pageQuery, queryWrapper);
    }

    @Override
    public void removeByUserId(Long userId) {
        this.remove(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
    }
}
